parallel-debian: More in progress work...
authorColin Walters <walters@verbum.org>
Thu, 20 Oct 2011 00:54:28 +0000 (20:54 -0400)
committerColin Walters <walters@verbum.org>
Thu, 20 Oct 2011 00:54:28 +0000 (20:54 -0400)
parallel-debian/README-testing-multiroot.md
parallel-debian/create-wheezy-image.sh [deleted file]
parallel-debian/make-image-parallel.sh [deleted file]
parallel-debian/ostree_switch_root.c

index 4fd0a1238395c86ce5d85f79cccb4a6037f3153a..1eadf88c5c71cb760f56035f9dcc78e86b549dff 100644 (file)
@@ -2,6 +2,12 @@
 Experimenting with multiple roots
 ---------------------------------
 
+       $ mkdir gnomeos-chroot 
+       $ qemu-img create gnomeos.raw 2G
+       $ mkfs.ext2 -F gnomeos.raw
+       $ mount -o loop gnomeos.raw gnomeos-chroot
+       $ debootstrap --arch=amd64 squeeze gnomeos-chroot
+
 <http://wiki.debian.org/QEMU#Setting_up_a_testing.2BAC8-unstable_system>
 
 Follow the steps for making a disk image, downloading the business
diff --git a/parallel-debian/create-wheezy-image.sh b/parallel-debian/create-wheezy-image.sh
deleted file mode 100755 (executable)
index 6f8263a..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#!/bin/sh
-
-set -e
-set -x
-
-if test -f debian.img; then
-  echo debian.img already exists
-  exit 1
-fi
-
-qemu-img create debian.img 600M
-mkfs.ext2 -q -F debian.img
-mkdir -p debian-mnt
-mount -o loop debian.img debian-mnt
-debootstrap --arch amd64 wheezy debian-mnt
-umount debian-mnt
diff --git a/parallel-debian/make-image-parallel.sh b/parallel-debian/make-image-parallel.sh
deleted file mode 100755 (executable)
index b6aaa9e..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/bin/sh
-
-set -e
-set -x
-
-DIRS="bin boot dev etc lib lib64 media mnt opt proc root run sbin selinux srv sys tmp usr var"
-
-if ! test -f debian.img; then
-  echo need debian.img
-  exit 1
-fi
-
-mount -o loop debian.img debian-mnt
-cd debian-mnt
-if ! test -d r0; then
-  mkdir r0
-  mv $DIRS r0
-fi
-cd ..
-umount debian-mnt
index 543dcb2b5ea92e5c7926cc002d59726c70776b54..67a1cc6803c4943d69d8dee1fa089a75aeafddc6 100644 (file)
@@ -143,7 +143,9 @@ static int make_readonly(const char *tree)
 
 static int switchroot(const char *newroot, const char *subroot)
 {
-       const char *root_bind_mounts[] = { "/home", "/root", "/var", NULL };
+       const char *toproot_bind_mounts[] = { "/boot", NULL };
+       const char *ostree_inherit_mounts[] = { "/home", "/root", NULL };
+       const char *ostree_bind_mounts[] = { "/var", NULL };
        const char *readonly_bind_mounts[] = { "/bin", "/etc", "/lib",
                                               "/lib32", "/lib64", "/sbin",
                                               "/usr",
@@ -151,13 +153,23 @@ static int switchroot(const char *newroot, const char *subroot)
        int i;
        int orig_cfd;
        int new_cfd;
+       int subroot_cfd;
        pid_t pid;
+       char subroot_path[PATH_MAX];
        char srcpath[PATH_MAX];
        char destpath[PATH_MAX];
+       struct stat stbuf;
 
        orig_cfd = open("/", O_RDONLY);
        new_cfd = open(newroot, O_RDONLY);
 
+       snprintf(subroot_path, sizeof(subroot_path), "%s/ostree/%s", newroot, subroot);
+       subroot_cfd = open(subroot_path, O_RDONLY);
+       if (subroot_cfd < 0) {
+               perrorv("failed to open subroot %s", subroot_path);
+               return -1;
+       }
+
        /* For now just remount the rootfs r/w.  Should definitely
         * handle this better later... (famous last words)
         */
@@ -166,11 +178,31 @@ static int switchroot(const char *newroot, const char *subroot)
                return -1;
        }
 
-       for (i = 0; root_bind_mounts[i] != NULL; i++) {
-               snprintf(srcpath, sizeof(srcpath), "%s%s", newroot, root_bind_mounts[i]);
-               snprintf(destpath, sizeof(destpath), "%s/%s%s", newroot, subroot, root_bind_mounts[i]);
+       for (i = 0; toproot_bind_mounts[i] != NULL; i++) {
+               snprintf(srcpath, sizeof(srcpath), "%s%s", newroot, toproot_bind_mounts[i]);
+               snprintf(destpath, sizeof(destpath), "%s/%s", subroot_path, toproot_bind_mounts[i]);
+               if (mount(srcpath, destpath, NULL, MS_BIND & ~MS_RDONLY, NULL) < 0) {
+                       perrorv("failed to bind mount (class:toproot) %s to %s", srcpath, destpath);
+                       return -1;
+               }
+       }
+
+       for (i = 0; ostree_inherit_mounts[i] != NULL; i++) {
+               snprintf(srcpath, sizeof(srcpath), "%s%s", newroot, ostree_inherit_mounts[i]);
+               if (stat (srcpath, &stbuf) < 0)
+                       snprintf(srcpath, sizeof(srcpath), "%s/ostree%s", newroot, ostree_inherit_mounts[i]);
+               snprintf(destpath, sizeof(destpath), "%s%s", subroot_path, ostree_inherit_mounts[i]);
+               if (mount(srcpath, destpath, NULL, MS_BIND & ~MS_RDONLY, NULL) < 0) {
+                       perrorv("failed to bind mount (class:inherit) %s to %s", srcpath, destpath);
+                       return -1;
+               }
+       }
+
+       for (i = 0; ostree_bind_mounts[i] != NULL; i++) {
+               snprintf(srcpath, sizeof(srcpath), "%s/ostree%s", newroot, ostree_bind_mounts[i]);
+               snprintf(destpath, sizeof(destpath), "%s%s", subroot_path, ostree_bind_mounts[i]);
                if (mount(srcpath, destpath, NULL, MS_BIND & ~MS_RDONLY, NULL) < 0) {
-                       perrorv("failed to bind mount %s to %s", srcpath, destpath);
+                       perrorv("failed to bind mount (class:bind) %s to %s", srcpath, destpath);
                        return -1;
                }
        }